package yxy.game.pm2.active.command.limitexchange;

import yxy.apple.logger.Logger;
import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.active.module.ActiveModule_限时兑换;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ActiveMessage;
import yxy.game.pm2.message.ActiveMessage.ActLimitExchangeInfoRequest;

@MessageType(proto = Command.ActLimitExchangeInfo, classtype = ActiveMessage.ActLimitExchangeInfoRequest.class)
public class CMD_Active_限时兑换_Info extends Command<ActLimitExchangeInfoRequest> {

	private static final Logger logger = Logger.create(CMD_Active_限时兑换_Info.class);
	
	@Override
	public void execute(MessageSource messageSource, ActLimitExchangeInfoRequest request) throws Exception {
		String pcode = messageSource.getTag();

		ActiveMessage.ActLimitExchangeInfoResponse.Builder response = ActiveMessage.ActLimitExchangeInfoResponse.newBuilder();
		
		ActiveModule_限时兑换 am = ActiveModule_限时兑换.get(pcode,false);
		if(am == null) {
			send(messageSource, response, Result.ActNoOpen);
			return;
		}
		
		if(!am.running()) {
			send(messageSource, response, Result.ActNoOpen);
			return;
		}
		
		response.setObtainend(am.getObtainend().getMillis());
		response.setExchangeend(am.getExchangeend().getMillis());
		
		send(messageSource, response, Result.Success);
	}

	
	private void send(MessageSource messageSource, ActiveMessage.ActLimitExchangeInfoResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}
